package dao;

import conexao.FabricaDeConexao;
import static dao.JDBCUsuarioDAO.getConecta;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConfirmaAcessoAdmDAO {
     private static FabricaDeConexao conecta = new FabricaDeConexao();
    Connection conexao;
    Statement st;
    ResultSet rs;
    String query;
    
     public ConfirmaAcessoAdmDAO(FabricaDeConexao conecta,
            Connection conexao, Statement st, ResultSet rs, String query) {
        JDBCUsuarioDAO.setConecta(conecta);
        this.conexao = conexao;
        this.st = st;
        this.rs = rs;
        this.query = query;
     }
     
      public boolean ValidaAcesso(String senha) {
        Connection con = getConecta().fazConexao();

        String sql = "SELECT * FROM senha WHERE secreta = '"+senha+"'";

        int sw = 0;
        try {

            PreparedStatement valores = (PreparedStatement) con.prepareStatement(sql);
            ResultSet result = (ResultSet) valores.executeQuery();

            if (result.next()) {
                if (result.getString(1) == null) {
                    sw = 0;
                } else {
                    sw = 1;
                }
            }
            valores.close();
        } catch (SQLException e) {
            System.out.println("Erro na inserçao de dados!" + e.getMessage());
        } finally {
            conecta.fechaConexao();
        }
        if (sw == 1) {
            return true;
        } else {
            return false;
        }
    }
}
